package day240602.e2;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

public class SetDomo {
    public static void main(String[] args) {
        Set<CustomObj> customObjs = new HashSet<>();
        customObjs.add(new CustomObj("X",1));
        customObjs.add(new CustomObj("Y",2));
        customObjs.add(new CustomObj("Z",3));

        System.out.println(customObjs.contains(new CustomObj("Y",2)));

        System.out.println(customObjs.size());
        System.out.println(customObjs);


    }
}

class CustomObj{
    String name;
    int value;

    public CustomObj(String name, int value) {
        this.name = name;
        this.value = value;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CustomObj customObj = (CustomObj) o;
        return value == customObj.value && Objects.equals(name, customObj.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, value);
    }

    @Override
    public String toString() {
        return "CustomObj{" +
                "name='" + name + '\'' +
                ", value=" + value +
                '}';
    }
}